#include "logindialog.h"
#include "ui_logindialog.h"

loginDialog::loginDialog(QWidget *parent) :
    QDialog(parent),
    m_ui(new Ui::loginDialog)
{
    m_ui->setupUi(this);
    m_ui->loginLine->setFocus();
}

loginDialog::~loginDialog()
{
    delete m_ui;
}

void loginDialog::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        m_ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

QString loginDialog::getLogin() const
{
    return m_ui->loginLine->text();
}

QString loginDialog::getPassword() const
{
    return m_ui->passwordLine->text();
}

void loginDialog::setLogin( const QString& login )
{
    if ( !login.isEmpty() )
    {
        m_ui->loginLine->setText( login );
        m_ui->loginLine->selectAll();
    }
}

void loginDialog::on_cancelButton_clicked()
{
    reject();
}

void loginDialog::on_okButton_clicked()
{
    if ( m_ui->passwordLine->text().isEmpty() )
    {
        QMessageBox::critical( this, tr("Login"), tr("Please type password") );
        return;
    }
    else if ( m_ui->loginLine->text().isEmpty() )
    {
        QMessageBox::critical( this, tr("Login"), tr("Please type login") );
        return;
    }
    accept();
}
